CONTENTS | INDEX | PREV | NEXT
 fstat

 NAME
  fstat - stat a file descriptor

 SYNOPSIS
  #include <sys/stat.h>

  int error = fstat(fd, &stat_buf);
  struct stat stat_buf;

 FUNCTION
  fstat() is a unix compatible call that returns information
  pertaining to the file represented by an open file descriptor.

  see stat() for information on the struct stat fields.

 NOTE
  fstat() works just like stat except you provide a UNIX file
  descriptor (*NOT* an amigaDOS File Handle).  Under 2.0,
  ExamineFH() will be used.  Under 1.3, the original path used to
  open the file will be stat()'d, which ends up scanning the
  directory if the file was open for exclusive access.

 INPUTS
  int fd;         file descriptor to stat

  struct stat *sbuf;  address of stat structure that will be filled in

 RESULTS
  int error;      0 on success, < 0 on error
  none

 EXAMPLE
  #include <stdio.h>
  #include <fcntl.h>
  #include <sys/stat.h>

  main(ac, av)
  int ac;
  char *av[];
  {
      int fd;
      int r;
      struct stat stat_buf;

      if (ac == 1) {
      puts("test scratch_file");
      exit(1);
      }
      fd = open(av[1], O_WRONLY | O_CREAT);
      if (fd >= 0) {
      r = fstat(fd, &stat_buf);
      if (r < 0)
          printf("Can't stat fd=%dn", fd);
      else
          printf("File is %d bytes longn", stat_buf.st_size);
      close(fd);
      }
      return(0);
  }

 SEE ALSO
  chdir